package com.hs.pk.berth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hs.pk.berth.bean.Berth;
import com.hs.pk.berth.bean.Road;
import com.hs.pk.berth.dto.RoadBerthDto;
import com.hs.pk.berth.mapper.BerthMapper;
import com.hs.pk.berth.service.IBerthService;
import com.hs.pk.berth.service.IRoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * berth 服务实现类
 * </p>
 *
 * @author lhj
 * @since 2022-07-20
 */
@Service
public class BerthServiceImpl extends ServiceImpl<BerthMapper, Berth> implements IBerthService {

    @Autowired
    private IRoadService roadService;

    @Override
    public RoadBerthDto findBerthDtoById(Long id) {

        //1. 根据泊位id查询对应泊位状态
        Berth berth = this.getById(id);

        //2. 根据泊位信息中的路段id查询路段名称
        LambdaQueryWrapper<Road> qw = Wrappers.lambdaQuery(Road.class);
        qw.select(Road::getName,Road::getId);
        qw.eq(Road::getId,berth.getRoadId());
        Road road = roadService.getOne(qw);

        //3. 把查询的数据设置到BerthDto中，返回
        RoadBerthDto roadBerthDto = new RoadBerthDto();
        roadBerthDto.setRoadId(road.getId());
        roadBerthDto.setBerthStatus(berth.getStatus());
        roadBerthDto.setRoadName(road.getName());


        return roadBerthDto;
    }
}
